home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_10_01
/
1001014d
< prev
next >
Wrap
Text File
|
1991-11-16
|
849b
|
47 lines
Listing 5 -- the file fclose.c
/* fclose function */
#include <stdlib.h>
#include "xstdio.h"
#include "yfuns.h"
int (fclose)(FILE *str)
{ /* close a stream */
int stat = fflush(str);
if (str->_Mode & _MALBUF)
free(str->_Buf);
str->_Buf = NULL;
if (0 <= str->_Handle && _Fclose(str))
stat = EOF;
if (str->_Tmpnam)
{ /* remove temp file */
if (remove(str->_Tmpnam))
stat = EOF;
free(str->_Tmpnam);
str->_Tmpnam = NULL;
}
str->_Mode = 0;
str->_Next = &str->_Cbuf;
str->_Rend = &str->_Cbuf;
str->_Wend = &str->_Cbuf;
str->_Nback = 0;
if (str->_Mode & _MALFIL)
{ /* find _Files[i] entry and free */
size_t i;
for (i = 0; i < FOPEN_MAX; ++i)
if (_Files[i] == str)
{ /* found entry */
_Files[i] = NULL;
break;
}
free(str);
}
return (stat);
}